package com.wzy.oa_sys.controller.attendance;

import com.wzy.oa_sys.model.request.attendance.StandardReq;
import com.wzy.oa_sys.service.attendance.TimeStandardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;

/**
 * 考勤标准
 */
@RestController
@RequestMapping("/standard")
public class StandardController {

    @Autowired
    private TimeStandardService timestandardService;

    @PostMapping("/addAttendanceStandard")
    public void addAttendanceStandard(@RequestBody StandardReq standardReq) {
        ZonedDateTime standardTime = standardReq.getStandardTime();
        ZonedDateTime newStandardTime = standardTime.withZoneSameInstant(ZoneId.of("Asia/Shanghai"));
        String formattedTime = newStandardTime.format(DateTimeFormatter.ISO_ZONED_DATE_TIME);
        System.out.println("=============="+formattedTime);

        standardReq.setStandardTime(newStandardTime);
        System.out.println("新增考勤标准："+standardReq.toString());
        timestandardService.addAttendanceStandard(standardReq);
    }
}
